<template>
  <div class="main">
    <div class="left">
      <div id="status"></div>
      <div id="sort"></div>
      <div id="equipment"></div>
      <div id="total"></div>
    </div>
    <div class="right">
      <div id="wOStatus"></div>
      <div id="wOTotal"></div>
      <div id="wOTime"></div>
      <div id="wONews">
        <h4>实时工单信息</h4>
        <div class="wo_mian">
          <div class=""></div>
          <div class="date" v-for="(item, index) in date" :key="index">
            <div class="date_l">{{ item.stuts }}</div>
            <div class="date_r">
              <p>{{ item.incident }}</p>
              <p>
                <span>处理人员：{{ item.processPersonnel }}</span
                ><span>{{ item.time }}</span>
              </p>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>
<script setup>
import * as echarts from "echarts";
import { init } from "echarts";
import { ref, onMounted, onUnmounted } from "vue";
import useFontSize from "@/hooks/useFontSize";
let { fontSize } = useFontSize();
// 告警状态统计
let statusCharts = ref(null);
let chartColor = "#fff";
let statusFn = () => {
  let option = {
    title: {
      text: "告警状态统计",
      textStyle: {
        color: chartColor,
        fontSize: 18,
      },
      left: 15,
      top: 15,
    },
    tooltip: {
      trigger: "item",
    },
    legend: {
      width: 32,
      top: "center",
      left: "60%",
      formatter: function (name) {
        let v;
        option.series[0].data.forEach((item) => {
          if (item.name === name) {
            v = item.value;
          }
        });
        let string= `${v}\n${name}`;
        return `${v}\n${name}`
      },
      textStyle: {
        color: chartColor,
      },
      selectedMode:false,
    },
    series: [
      {
        name: "Access From",
        type: "pie",
        center: ["30%", "50%"],
        radius: ["40%", "50%"],
        avoidLabelOverlap: false,
        itemStyle: {
          borderRadius: 2,
          borderColor: "#adadad",
          borderWidth: 2,
        },
        label: {
          show: true,
          position: "center",
          formatter: "9\n告警数",
          color:chartColor,
          fontSize: 16,
          // fontWeight: "bold",
        },
        labelLine: {
          show: false,
        },
        data: [
          {
            value: 1048,
            name: "Search Engine",
            itemStyle: {
              color: new echarts.graphic.RadialGradient(0, 0, 1, [
                {
                  offset: 0,
                  color: "rgb(129, 227, 238,0.2)", // 0% 处的颜色
                },
                {
                  offset: 1,
                  color: "rgb(129, 227, 238,0.8)", // 100% 处的颜色
                },
              ]),
            },
          },
          { value: 735, name: "Direct" },
          { value: 580, name: "Email" },
        ],
      },
    ],
  };
  statusCharts = echarts.init(document.getElementById("status"));
  statusCharts.setOption(option);
};
// 告警分类统计
let sortCharts = ref(null);
let sortFn = () => {
  let option = {
    title: {
      text: "分享用电统计",
      textStyle: {
        color: chartColor,
        fontSize: 18,
      },
      top: 15,
      left: 15,
    },
    xAxis: {
      type: "category",
      data: ["冷水机组", "末端空调"],
      axisTick: {
        show: false,
      },
      axisLabel: {
        color: chartColor,
      },
    },
    yAxis: {
      type: "value",
      min: 0,
      max: 300,
      splitLine: {
        show: false,
      },
      axisLabel: {
        color: chartColor,
      },
    },
    series: [
      {
        data: [0, 3],
        type: "bar",
        label: {
          show: true,
          position: "top",
          color: chartColor,
        },
        itemStyle: {
          color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
            { offset: 0, color: "rgba(6, 120, 238,0.8)" }, // 渐变色起始值
            { offset: 1, color: "rgba(6, 120, 238,0.2)" }, // 渐变色结束值
          ]),
        },
      },
      {
        data: [0, 1],
        type: "bar",
        label: {
          show: true,
          position: "top",
          color: chartColor,
        },
        itemStyle: {
          color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
            { offset: 0, color: "rgba(19, 164, 175,0.8)" }, // 渐变色起始值
            { offset: 1, color: "rgba(19, 164, 175,0.2)" }, // 渐变色结束值
          ]),
        },
      },
      {
        data: [130, 192],
        type: "bar",
        label: {
          show: true,
          position: "top",
          color: chartColor,
        },
        itemStyle: {
          color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
            { offset: 0, color: "rgba(108, 185, 68,0.8)" }, // 渐变色起始值
            { offset: 1, color: "rgba(108, 185, 68,0.2)" }, // 渐变色结束值
          ]),
        },
      },
    ],
  };
  sortCharts = echarts.init(document.getElementById("sort"));
  sortCharts.setOption(option);
};
// 重要设备可用率
let equipmentCharts = ref(null);
let equipmentFn = () => {
  let option = {
    title: {
      text: "重要设备可用率",
      textStyle: {
        color: chartColor,
        fontSize: 18,
      },
      top: 15,
      left: 15,
    },
    xAxis: {
      type: "category",
      data: ["摄像头", "门禁", "闸机"],
      axisTick: {
        show: false,
      },
      axisLabel:{
        color:chartColor
      }
    },
    yAxis: {
      type: "value",
      axisLabel: {
        formatter: "{value}%",
      },
      min: 0,
      max: 300,
      splitLine: {
        show: false,
      },
      axisLabel:{
        color:chartColor
      }
    },
    series: [
      {
        data: [98, 100, 100],
        type: "bar",
        label: {
          show: true,
          position: "top",
          formatter: "{c}%",
          color:chartColor
        },
        barWidth: "30%",
        itemStyle: {
          color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
            { offset: 0, color: "rgba(6, 120, 238,0.8)" }, // 渐变色起始值
            { offset: 1, color: "rgba(6, 120, 238,0.2)" }, // 渐变色结束值
          ]),
        },
      },
    ],
  };
  equipmentCharts = echarts.init(document.getElementById("equipment"));
  equipmentCharts.setOption(option);
};
// 告警统计
let totalCharts = ref(null);
let totalFn = () => {
  let option = {
    title: {
      text: "告警状态统计",
      textStyle: {
        color: chartColor,
        fontSize: 18,
      },
      left: 15,
      top: 15,
    },
    tooltip: {
      trigger: "item",
    },
    legend: {
      width: 20,
      top: "center",
      left: "60%",
      formatter: function (name) {
        let v;
        option.series[0].data.forEach((item) => {
          if (item.name === name) {
            v = item.value;
          }
        });
        let string= `${v}\n${name}`;
        return string;
      },
      textStyle: {
        color: chartColor,
      },
      selectedMode:false,
    },
    series: [
      {
        name: "Access From",
        type: "pie",
        center: ["30%", "50%"],
        radius: ["40%", "50%"],
        avoidLabelOverlap: false,
        itemStyle: {
          borderRadius: 2,
          borderColor: "#adadad",
          borderWidth: 2,
        },
        label: {
          show: true,
          position: "center",
          formatter: "4\n总数",
          fontSize: 16,
          color:chartColor
        },
        labelLine: {
          show: false,
        },
        data: [
          {
            value: 4,
            name: "Search Engine",
            itemStyle: {
              color: {
                type: "linear",
                x: 0,
                y: 0,
                x2: 0,
                y2: 1,
                colorStops: [
                  {
                    offset: 0,
                    color: "rgba(19,161,169,0.2)", // 0% 处的颜色
                  },
                  {
                    offset: 0.5,
                    color: "rgba(19,161,169,0.5)", // 0% 处的颜色
                  },
                  {
                    offset: 1,
                    color: "rgba(19,161,169,0.8)", // 100% 处的颜色
                  },
                ],
                global: false, // 缺省为 false
              },
            },
          },
          {
            value: 0,
            name: "Direct",
            itemStyle: {
              color: {
                type: "linear",
                x: 0,
                y: 0,
                x2: 0,
                y2: 1,
                colorStops: [
                {
                    offset: 0,
                    color: "rgba(25,16,199,0.2)", // 0% 处的颜色
                  },
                  {
                    offset: 0.5,
                    color: "rgba(25,16,199,0.5)", // 0% 处的颜色
                  },
                  {
                    offset: 1,
                    color: "rgba(25,16,199,0.8)", // 100% 处的颜色
                  },
                ],
                global: false, // 缺省为 false
              },
            },
          },
        ],
      },
    ],
  };
  totalCharts = echarts.init(document.getElementById("total"));
  totalCharts.setOption(option);
};
// 工单状态统计
let wOStatusCharts = ref(null);
let wOStatusFn = () => {
  let option = {
    title: {
      text: "工单状态统计",
      textStyle: {
        fontSize: 18,
        color:chartColor,
        // fontWeight: "bold",
      },
      top: 15,
      left: 15,
    },
    tooltip: {
      trigger: "item",
    },
    legend: {
      width: 20,
      top: "center",
      left: "60%",
      formatter: function (name) {
        let v;
        // console.log(option.series[0].data);
        option.series[0].data.forEach((item) => {
          if (item.name === name) {
            v = item.value;
          }
        });
        let string= `${v}\n${name}`;
        return string;
      },
      textStyle: {
        color: chartColor,
      },
      selectedMode:false,
    },
    series: [
      {
        name: "Access From",
        type: "pie",
        center: ["30%", "50%"],
        radius: ["40%", "50%"],
        avoidLabelOverlap: false,
        itemStyle: {
          borderRadius: 2,
          borderColor: "#dddddd",
          borderWidth: 2,
        },
        label: {
          show: true,
          formatter: "1,108\n总数",
          fontSize: 16,
          position: "center",
          color:chartColor
        },
        labelLine: {
          show: false,
        },
        data: [
          {
            value: 580,
            name: "Email",
            itemStyle: {
              color: new echarts.graphic.LinearGradient(0, 0, 1, 1, [
                { offset: 0, color: "rgba(1, 116, 249,0.2)" }, // 渐变色起始值
                { offset: 1, color: "rgba(1, 116, 249,0.8)" }, // 渐变色结束值
              ]),
            },
          },
          {
            value: 484,
            name: "Union Ads",
            itemStyle: {
              color: new echarts.graphic.LinearGradient(0, 0, 1, 1, [
                { offset: 0, color: "rgba(89, 156, 64,0.2)" }, // 渐变色起始值
                { offset: 1, color: "rgba(89, 156, 64,0.8)" }, // 渐变色结束值
              ]),
            },
          },
          {
            value: 300,
            name: "Video Ads",
            itemStyle: {
              color: new echarts.graphic.LinearGradient(0, 0, 1, 1, [
                { offset: 0, color: "rgba(24, 151, 160,0.2)" }, // 渐变色起始值
                { offset: 1, color: "rgba(24, 151, 160,0.8)" }, // 渐变色结束值
              ]),
            },
          },
        ],
      },
    ],
  };
  wOStatusCharts = echarts.init(document.getElementById("wOStatus"));
  wOStatusCharts.setOption(option);
};
// 工单统计
let wOTotalCharts = ref(null);
let wOTotalFn = () => {
  let option = {
    title: {
      text: "工单统计",
      textStyle: {
        fontSize: 18,
        color: chartColor,
      },
      top: 15,
      left: 15,
    },
    xAxis: {
      type: "category",
      data: ["2022-10", "2022-11", "2022-12", "2023-01", "2023-02", "2023-03"],
      axisTick: {
        show: false,
      },
      axisLabel:{
        color:chartColor
      }
    },
    yAxis: {
      type: "value",
      min: 0,
      max: 200,
      axisLine: {
        show: false,
      },
      splitLine: {
        show: false,
      },
      axisLabel:{
        color:chartColor
      }
    },
    series: [
      {
        label: {
          show: true,
          position: "top",
          color:chartColor
        },
        barWidth: 30,
        data: [120, 200, 150, 80, 70, 110],
        type: "bar",
      },
    ],
  };
  wOTotalCharts = init(document.getElementById("wOTotal"));
  wOTotalCharts.setOption(option);
};
// 工单平均时长
let wOTimeCharts = ref(null);
let wOTimeFn = () => {
  let option = {
    title: {
      text: "工单平均响应时长",
      textStyle: {
        fontSize: 18,
        color: chartColor,
      },
      top: 15,
      left: 15,
    },
    xAxis: {
      type: "category",
      boundaryGap: false,
      axisTick: {
        show: false,
      },
      data: ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"],
      axisLabel:{
        color:chartColor
      }
    },
    yAxis: {
      type: "value",
      axisLine: {
        show: false,
      },
      splitLine: {
        show: false,
      },
      axisLabel:{
        color:chartColor
      }
    },
    series: [
      {
        data: [820, 932, 901, 934, 1290, 1330, 1320],
        type: "line",
        smooth: true,
        areaStyle: {},
      },
    ],
  };
  wOTimeCharts = echarts.init(document.getElementById("wOTime"));
  wOTimeCharts.setOption(option);
};
// 实时工单信息
let date = ref([
  {
    stuts: "待处理",
    incident: "J1-2A茶水间洗杯子的池子堵住了",
    processPersonnel: "孙红勇",
    time: "2019-09-10 11:49:51",
  },
  {
    stuts: "待处理",
    incident: "J1-2A茶水间洗杯子的池子堵住了",
    processPersonnel: "孙红勇",
    time: "2019-09-10 11:49:51",
  },
  {
    stuts: "待处理",
    incident: "J1-2A茶水间洗杯子的池子堵住了",
    processPersonnel: "孙红勇",
    time: "2019-09-10 11:49:51",
  },
  {
    stuts: "待处理",
    incident: "J1-2A茶水间洗杯子的池子堵住了",
    processPersonnel: "孙红勇",
    time: "2019-09-10 11:49:51",
  },
]);
onMounted(() => {
  statusFn();
  sortFn();
  equipmentFn();
  totalFn();
  wOStatusFn();
  wOTotalFn();
  wOTimeFn();
  window.addEventListener("resize", () => {
    sortCharts.resize();
    statusCharts.resize();
    equipmentCharts.resize();
    totalCharts.resize();
    wOStatusCharts.resize();
    wOTotalCharts.resize();
    wOTimeCharts.resize();
  });
});
onUnmounted(() => {
  sortCharts.dispose();
  statusCharts.dispose();
  equipmentCharts.dispose();
  totalCharts.dispose();
  wOStatusCharts.dispose();
  wOTotalCharts.dispose();
  wOTimeCharts.dispose();
});
</script>
<style scoped>

.left {
  float: left;
  width: 4rem;
  height: 100%;
}
.left > div {
  width: 100%;
  height: 2.1rem;
  background: url("@/assets/bj1.png") no-repeat;
  background-size: 100% 100%;
}
.right {
  float: right;
  width: 4rem;
  height: 100%;
}
.right > div {
  width: 100%;
  height: 2.1rem;
  background: url("@/assets/bj2.png") no-repeat;
  background-size: 100% 100%;
  overflow: hidden;
}
#wONews h4 {
  color: var(--text-color);
  font-size: 18px;
  padding: 0.15rem 0 0 0.15rem;
}
.wo_mian {
  overflow-y: auto;
  overflow-x: hidden;
  height: 1.8rem;
  padding: 0.2rem 0 0 0;
}
/* // 滚动条 */
.wo_mian::-webkit-scrollbar {
  /*滚动条整体样式*/
  width: 0.1rem; /*高宽分别对应横竖滚动条的尺寸*/
  height: 1px;
}
.wo_mian::-webkit-scrollbar-thumb {
  /*滚动条里面小方块*/
  border-radius: 2px;
  height: 0.2rem;
  -webkit-box-shadow: inset 0 0 5px rgba(0, 0, 0, 0.2);
  /* // background: #E5E5E5; */
  background: #067bfb;
}
.wo_mian::-webkit-scrollbar-track {
  /*滚动条里面轨道*/
  -webkit-box-shadow: inset 0 0 5px rgba(0, 0, 0, 0.2);
  border-radius: 2px;
  background: #747474;
}

.date {
  display: flex;
  margin: 0.05rem 0 0 0;
  width: 4rem;
  padding-left: 0.05rem;
}
.date_l {
  margin: 0 0.08rem 0 0;
  font-size: 12px;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  line-height: 40px;
  text-align: center;
  color: var(--text-color);
  background-color: #e9a644;
}
.date_r {
  /* width: 15vw; */
  color:var(--text-color);
  flex: 1;
  font-size: 14px;
}
.date_r p:last-child span:last-child {
  float: right;
  margin-right: 0.7rem;
}
</style>
